package com.shanglida.utils;

import android.app.Service;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.IBinder;
import android.widget.Toast;
import com.shanglida.R;

/**
 * @author maus
 * @deprecated 监控网络状态 仅在无网络的情况下弹出提示内容
 * @date 2014-02-26 PM
 * @version 1.0
 */
public class NetWork extends Service {
	// 基于什么网络 mconn
	public ConnectivityManager mconn;
	// minfo 网络信息
	public NetworkInfo minfo;
	// mbroad广播接收者
	public BroadcastReceiver mbroad = new BroadcastReceiver() {
		@Override
		public void onReceive(Context context, Intent intent) {
			String action = intent.getAction();
			if (action.equals(ConnectivityManager.CONNECTIVITY_ACTION)) {
				mconn = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
				minfo = mconn.getActiveNetworkInfo();
				if (minfo != null && minfo.isAvailable()) {
				} else {
					Toast.makeText(NetWork.this, R.string.error_network,
							Toast.LENGTH_SHORT).show();
				}
			}
		}
	};

	@Override
	public IBinder onBind(Intent intent) {
		return null;
	}

	@Override
	public void onCreate() {
		super.onCreate();
		IntentFilter mFilter = new IntentFilter();
		mFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
		registerReceiver(mbroad, mFilter);
	}

	@Override
	public void onDestroy() {
		super.onDestroy();
		unregisterReceiver(mbroad);
	}

	@Override
	public int onStartCommand(Intent intent, int flags, int startId) {
		return super.onStartCommand(intent, flags, startId);

	}

}
